#2017年省赛-填空题 等差素数列
import math
# 判断素数
def check(n):
    for i in range(2, int(math.sqrt(n)) + 1):
        if n % i == 0:
            return False
    return True

flag = False
sub = 0 #公差
for i in range(2, 1000):
    if check(i) == False:
        continue
    else:
        for j in range(1, 1000):  #枚举公差
            a = [i]
            for k in range(i + j, i + 9 * j + 1, j):
                if check(k) == False:
                    break
                else:
                    a.append(k)
                #满足长度为10，记录公差，退出循环
                if len(a) == 10:
                    sub = j
                    flag = True
                    break
            if flag:
                break
        if flag:
            break
print(sub)